<!DOCTYPE html> 
<html lang="zh-CN"> 
<head> 
    <meta charset="UTF-8"> 
    <title>2*num+1 计算</title> 
</head> 
<body> 
    <input id="numInput" placeholder="输入数字" /> 
    <button id="calcBtn">计算</button> 
    <div id="result"></div> 
    <script> 
        const input = document.getElementById('numInput'); 
        const btn = document.getElementById('calcBtn'); 
        const result = document.getElementById('result'); 
        btn.onclick = () => { 
            fetch('/api/calc?num=' + encodeURIComponent(input.value)) 
                .then(res => res.json()) 
                .then(data => { 
                    if (data.error) { 
                        result.textContent = data.error; 
                    } else { 
                        result.textContent = '输入: ' + data.input + ',结果: ' + data.result; 
                    } 
                }) 
                .catch(err => { 
                    result.textContent = '请求失败'; 
                }); 
        }; 
    </script> 
</body> 
</html>